package com.gxs.ea.fileupload.beans.jsf;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.gxs.ea.fileupload.beans.data.model.User;
import com.gxs.ea.fileupload.beans.utils.AuthUtils;
import com.gxs.ea.fileupload.beans.utils.JSFUtils;

@Component
@Scope("session")
public class HomeBean implements Serializable
{
	
	@Autowired
	AuthUtils authUtils;
	
	@Autowired
	JSFUtils jsfUtils;
	
	private boolean companyCheckDone = false;
	
	
	public void performCompanyCheck() throws Exception
	{
		if(companyCheckDone)
		{
			return;
		}
		else
		{
			User user = authUtils.getDetailsForLoggedInUser();
			if(user.getCompany() == null)
			{
				jsfUtils.printError("Invalid Company Assignment", "Your id is not assigned to a valid company and you will not be able to perform company related operations");
			}
			companyCheckDone = true;
		}
	}

	public AuthUtils getAuthUtils() {
		return authUtils;
	}

	public void setAuthUtils(AuthUtils authUtils) {
		this.authUtils = authUtils;
	}
	
	
}